import java.util.Objects;

public class Student implements Comparable<Student>{
        private String name;
        private int age;
        public Student(){}
        public Student(String name,int age){
            this.name = name;
            this.age = age;
        }
        public void setName(String name){
            this.name = name;
        }
        public String getName(){
            return name;
        }
        public void setAge(int age){
            this.age = age;
        }
        public int getAge(){
            return age;
        }
        public void study(){
            System.out.println("Studying!");;
        }
        public void doHomework(){
            System.out.println("Doing Homework!");
        }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(name, student.name) && Objects.equals(age, student.age);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }


    @Override
    public int compareTo(Student s) {
        int num = this.age - s.age;   // 按年龄从小到大排序
        int ret = num == 0 ? this.name.compareTo(s.name) : num;  //如果年龄相同，则按姓名字母字典序
        return ret;
    }
}


